export function transListToTreeData(arr) {
  const parent = arr.filter(item => !item.p_id)

  parent.forEach(item1 => {
    item1.children = arr.filter(item2 => item1.id === item2.p_id)
  })

  return parent
}

export function handleFormData(fromData) {
  for (const k in fromData) {
    if (typeof fromData[k] === 'string') {
      fromData[k] = fromData[k].trim()
      // if (fromData[k] === '') {
      //   fromData[k] = null
      // }
    }
  }
}

export function removeNoChangeValue(newFormData, oldFromData) {
  const res = {}

  for (const k in newFormData) {
    if (newFormData[k] !== oldFromData[k]) {
      res[k] = newFormData[k]
    }
  }
  if (Object.keys(res).length === 0) {
    return false
  } else {
    res.id = newFormData.id
    return res
  }
}
